// Render a link for mapping objects to Yahoo! Maps.
// version 1.0
// 2006-07-08
// Copyright (c) 2006, Calvin Yu
//
// --------------------------------------------------------------------
//
// This is a Tails script.
//
// To install, you need Tails: http://blog.codeeg.com/tails-firefox-extension/
// Then restart Firefox and revisit this script and click on 'Install'.
//
// To uninstall, go to Tools/Manage Tails Scripts...,
// select "Map with Yahoo!", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==TailsScript==
// @name          Map with Yahoo!
// @namespace     http://blog.codeeg.com/tails
// @description   Render a link for mapping objects to Yahoo! Maps.
// @include       hcard
// @include       hcalendar
// @include       hreview
// ==/TailsScript==

getURL: function() {
  if (this.object.__name == "hcard") {
    return this.buildURL(this.object);
  } else if (this.object.__name == "hcalendar" && this.object.location_hcard) {
    return this.buildURL(this.object.location_hcard);
  } else if (this.object.__name == "hreview" && this.object.item_hcard) {
    return this.buildURL(this.object.item_hcard);
  }
},
buildURL: function(hcard) {
  if ((hcard.locality && hcard.region)
      || hcard['postal-code']) {

    var cityStateZip = hcard.toLocalityRegionAndPostalCodeString();
    var url = "http://maps.yahoo.com/maps_result?addr=";
    if (hcard['street-address']) url += hcard['street-address'].replace(/\s+/g, '+');
    url += "&csz=" + cityStateZip.replace(/\s+/g, '+') + "&new=1&name=&qty=";
    return url;
  }
}
